package com.tangqihang229350526.mynote.repository

import com.tangqihang229350526.mynote.database.User
import com.tangqihang229350526.mynote.database.UserDao
import com.tangqihang229350526.mynote.database.UserDatabase
import com.tangqihang229350526.mynote.viewmodel.LoginViewModel
import com.tangqihang229350526.mynote.viewmodel.RegisterViewModel

class UserRepository private constructor() : UserDao {
    override val userData: User = User("tangshuai", USERNAME, PASSWORD)

    override fun login(user:UserDatabase,viewModel: LoginViewModel?, username: String?, password: String?) {
        viewModel?.setIsRight(user.login(username, password))
    }

    override fun register(user:UserDatabase,viewModel: RegisterViewModel?,username: String?, password: String?)
    {
        viewModel?.setIsRight(user.register(username, password))
    }
    companion object {
        private const val USERNAME = "tangshuai"
        private const val PASSWORD = "229350526"
        private var INSTANCE: UserRepository? = null
        val instance: UserRepository?
            get() {
                if (INSTANCE == null) {
                    INSTANCE = UserRepository()
                }
                return INSTANCE
            }
    }
}